<template>
    <div>
      <ul>
    <li v-for="product in products" :key="product.id">
      {{ product.title }} - {{ product.price }}
      <br />
      <button :disabled="!product.inventory" @click="addProductToCart(product)">
        Add to cart
      </button>
    </li>
  </ul>
    </div>
</template>

<script>
    import {createNamespacedHelpers} from 'vuex'
    const{
        mapState:productMapState,
        mapActions:productMapActions
    } = createNamespacedHelpers('product');
    const {
        mapActions:cartMapActions
    } = createNamespacedHelpers('cart');
    export default {
        computed: {
            ...productMapState({
                products:state => state.all
            }),

        },
        methods: {
            ...productMapActions(["getAllProducts"]),
            ...cartMapActions(["addProductToCart"])
        },
        created(){
           this.getAllProducts()
        }
    }
</script>

<style lang="scss" scoped>

</style>